/* 
 * File:   player.h
 * Author: iezahel
 *
 * Created on December 27, 2008, 12:58 PM
 */

#ifndef _PLAYER_H
#define	_PLAYER_H

#include <sys/socket.h>
#include <arpa/inet.h>

#include <math.h>

#include "pong.h"
#include "game_protocol.h"
#include "ball.h"
#include "networkcommunication.h"

class Player {
private:
    double x, y;
    int velocity;
    int score;
    int default_player_speed;
    
    int player_w, player_h;
    int screen_w, screen_h;
    
    SDL_Surface* screen_surface;
    SDL_Surface* player_surface;

    NetworkCommunication* comm;

    bool is_paused;

    void draw_text_on_screen(TTF_Font* game_font, const char* text, int x, int y);
    double distance_to_ball(const Ball* ball) const;
    double distance(double x1, double y1, double x2, double y2) const { return sqrt(SQR(x2 - x1) + SQR(y2 - y1)); }
protected:
    char* hostname;
    short host_port;      
    
public:
    Player(SDL_Surface*, SDL_Surface*, NetworkCommunication*, int, int);
    Player(const Player& orig);
    virtual ~Player();  
    
    int GetScore() const { return score; }
    int SetScore(int s) { score = (s >= 0) ? s : 0; }
    void IncScore() { score++; }

    int GetY() const { return y; }

    int GetPosition() const { return x == 0 ? GAME_PLAYER_POS_LEFT : GAME_PLAYER_POS_RIGHT; }
    
    void SetVelocity(double val) { velocity = val; }
    double GetVelocity() const { return velocity; }    

    bool BallIsInDangerRegion(const Ball* ball) const;
    
    GAME_ERROR_CODES HandleKeyboardInput(SDL_Event* event);
    GAME_ERROR_CODES HandleNetworkInput(SDL_Event* event);

    bool CheckBallCollision(Ball* ball);

    void SetPause(bool p = true) { is_paused = p; }
    bool IsPaused() const { return is_paused; }

    void draw_score(TTF_Font*);
    void draw_pause_msg(TTF_Font*);

    void draw();
    void move(int delta_t);
    
   
};

#endif	/* _PLAYER_H */

